package com.foreknow.elm.service.impl;

import com.foreknow.elm.dao.OrderDetailetDao;
import com.foreknow.elm.dao.impl.OrderDetailetIDaompl;
import com.foreknow.elm.po.OrderDetailet;
import com.foreknow.elm.service.OrderDetailetService;
import com.foreknow.elm.util.DBUtil;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class OrderDetailetServiceImpl implements OrderDetailetService {
    OrderDetailetDao orderDetailetDao = new OrderDetailetIDaompl();
    //添加订单明细
    @Override
    public int save(List<OrderDetailet> orderdetailet) {
        int a = 0;
        try {
            DBUtil.beginTransaction();
            a = orderDetailetDao.save(orderdetailet);
            DBUtil.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            try {
                DBUtil.rollbackTransaction();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
            try {
                DBUtil.rollbackTransaction();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }finally {
            DBUtil.close();
        }
        return a;
    }
//根据orderid查询订单明细,返回集合
    @Override
    public List<OrderDetailet> query(Integer orderId) {
        List<OrderDetailet> list = new ArrayList<>();
        try {
            list = orderDetailetDao.query(orderId);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close();
        }
        return list;
    }
}
